import { defineStore } from 'pinia';
// import router from '@/router';
const useMenuStore = defineStore('menu', {
	state: () => {
		return {
			loginInfo:uni.getStorageSync('loginInfo') || {},
			menuInfo:{
				defaultAct:'0',
				defaultOpen:[],
				pageTitle:'首页',
				isCollapse:false
			}
		};
	},
	actions: {
		setMenu(username: string, permission: string[],token:string,buttons: string[]) {
			this.loginInfo.permitUrl = permission;
			this.loginInfo.buttons = buttons||[]
			this.loginInfo.username = username;
			// this.loginInfo.tree = router;
			this.loginInfo.token = token;
			// this.loginInfo.flattenTree = this.flattenMenuTree(router)
			uni.setStorageSync('loginInfo',this.loginInfo)
		}
		// ,

		// // 将tree转为一维数组
		//  flattenMenuTree (menutree:typeof router):string[]{
		// 	let result = [];
		// 	for (let i = 0; i < menutree.length; i++) {
		// 		let node = menutree[i];
		// 		if (node.children && node.children.length > 0) {
		// 			let children = this.flattenMenuTree(node.children);
		// 			result = result.concat(children);
		// 		}
		// 		result.push(node);
		// 	}
		// 	return result;
		// },
	}
});
export default useMenuStore;


